import 'dart:convert';
import 'dart:math';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:get/get_navigation/src/routes/transitions_type.dart';
import 'package:flutter/services.dart' show rootBundle;
import 'package:niu_app/pages/model/homepage/dynamics_model.dart';
import 'package:niu_app/views/homepage/dynamics_widget.dart';
import 'package:niu_app/views/homepage/jk_over_scroll_behavior.dart';
import 'enlite_dynamic_page.dart';

class dynamics_Page extends StatefulWidget {
  @override
  _DynamicPageState createState() => _DynamicPageState();
}

class _DynamicPageState extends State<dynamics_Page> {

  List dataSource = [];
  @override
  void initState() {
    // TODO: implement initState
    super.initState();

    loadAsset();

  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white,
      floatingActionButton: FloatingActionButton(child: Icon(Icons.edit),onPressed:()=> Get.to(EditeDynamicPage(),transition: Transition.cupertino),),
      body: Container(
        padding: EdgeInsets.symmetric(horizontal: 16.w),
        child: ScrollConfiguration(
          behavior: JKOverScrollBehavior(), // 去除下拉水波纹效果
          child: ListView.builder(
            physics: NeverScrollableScrollPhysics(),
            itemBuilder: (context, index) {
              return DynamicCellWidget(dataModel: dataSource[index],);
            },
            itemCount: dataSource.length,
          ),
        ),
      ),
    );
  }





  // 加载本地数据
  loadAsset() async {
    var value = await rootBundle.loadString('data/mocks/mock_dynamic_data.json');
    List jsonList = json.decode(value);
    jsonList.forEach((element) {
      dataSource.add(DynamicDataModel.fromJsonMap(element));
    });
    // dataSource.add(value)
    print(jsonList.toString());
    setState(() {
    });
  }

}

